package org.apache.ocean.main.search;

import org.apache.ocean.main.Index.IndexSnapshot;
import org.apache.ocean.util.DocSet;

public abstract class IndexSnapshotFilter {
	private IndexSnapshot indexSnapshot;

	public IndexSnapshotFilter(IndexSnapshot indexSnapshot) {
		this.indexSnapshot = indexSnapshot;
	}

	public abstract DocSet getDocSet();

	public abstract boolean contains(int doc);
  /**
	public static class FieldCacheRangeSnapshotFilter extends IndexSnapshotFilter {
		private String field;
		private Range range;
		private IndexSnapshot indexSnapshot;
		private final Comparable[] array;

		public FieldCacheRangeSnapshotFilter(String field, Range range, IndexSnapshot indexSnapshot) {
			super(indexSnapshot);
			this.field = field;
			this.range = range;
			array = indexSnapshot.getFieldArray(field);
		}

		public ResultFilter getResultFilter() {
			if (range.isIncludeLower() && range.isIncludeUpper()) {
				return new ResultFilter() {
					public boolean contains(int doc) {
				    int lowerCompare = array[doc].compareTo(range.getLowerVal());
				    int upperCompare = array[doc].compareTo(range.getUpperVal());
				    if ( (lowerCompare == 0 || lowerCompare == 1) 
						  && (upperCompare == 0 || upperCompare == -1)) { 
					    return true;
				    } 
				    return false;
				  }
				};
			} else if (range.isIncludeLower() && !range.isIncludeUpper()) {
				return new ResultFilter() {
					public boolean contains(int doc) {
				    int lowerCompare = array[doc].compareTo(range.getLowerVal());
				    int upperCompare = array[doc].compareTo(range.getUpperVal());
				    if ( (lowerCompare == 0 || lowerCompare == 1) 
						  && (upperCompare == -1)) { 
					    return true;
				    } 
				    return false;
				  }
				};
			} else if (!range.isIncludeLower() && range.isIncludeUpper()) {
				return new ResultFilter() {
					public boolean contains(int doc) {
						int lowerCompare = array[doc].compareTo(range.getLowerVal());
				    int upperCompare = array[doc].compareTo(range.getUpperVal());
				    if ( (lowerCompare == 1) 
						  && (upperCompare == 0 || upperCompare == -1)) { 
					    return true;
				    } 
				    return false;
				  }
				};
			} else {
				return new ResultFilter() {
					public boolean contains(int doc) {
						int lowerCompare = array[doc].compareTo(range.getLowerVal());
				    int upperCompare = array[doc].compareTo(range.getUpperVal());
				    if (lowerCompare == 1 && upperCompare == -1) { 
					    return true;
				    } 
				    return false;
				  }
				};
			}
		}
	}
	**/
}
